package com.tvein.sanguo.action.controller.room
{
	//flash
	//pureMVC
	import flash.display.DisplayObject;
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.command.SimpleFabricationCommand;
	//custom
	import com.tvein.sanguo.action.view.ActionMediator;
	import com.tvein.sanguo.action.model.SystemProxy;
	import com.tvein.sanguo.swc.action.room.Room2;
	import com.tvein.sanguo.swc.action.room.Room3;
//
	public class ActionRoom extends SimpleFabricationCommand implements ICommand
	{
		private var actionMediator:ActionMediator;
		private var systemData:SystemProxy;
		
		override public function execute(notification:INotification) : void
		{
			actionMediator = facade.retrieveMediator(ActionMediator.NAME) as ActionMediator;
			systemData = facade.retrieveProxy(SystemProxy.NAME) as SystemProxy;
			
			clearChild();
			
			var params:Object = new Object();
			
			switch (notification.getBody().Main.id)
			{
				case 2:		//Challenge Finish
					var actionRoom2:Room2 = new Room2();
					actionMediator.action.addChild(actionRoom2);
					actionRoom2.name = "Room-2";
					
					params.Address = systemData.srcServer;
					actionRoom2.console("setSource", params);
					params.Volume = systemData.effectVol;
					actionRoom2.console("setEffect", params);
					
					actionRoom2.console("setRoom", notification.getBody().Name);
					actionRoom2.console("setData", notification.getBody().Process);
					actionRoom2.addEventListener("Room-2", actionMediator._handleEvents);
					
					break;
				case 3:		//Argue Finish
					var actionRoom3:Room3 = new Room3();
					actionMediator.action.addChild(actionRoom3);
					actionRoom3.name = "Room-3";

					params.Address = systemData.srcServer;
					actionRoom3.console("setSource", params);
					params.Volume = systemData.effectVol;
					actionRoom3.console("setEffect", params);
					
					actionRoom3.console("setRoom", notification.getBody().Name);
					actionRoom3.console("setData", notification.getBody().Process);
					actionRoom3.addEventListener("Room-3", actionMediator._handleEvents);
					
					break;
				case 4:		//Battle Finish

					break;
			}
		}
		
		private function clearChild():void
		{
			for (var i:int = actionMediator.action.numChildren - 1; i >= 0; i--)
			{
				actionMediator.action.removeChildAt(0); 
			}
		}
	}
}